"use server";
import {getQuestionVoByIdUsingGet} from "@/api/questionController";
import QuestionCard from "@/components/QuestionCard";
import ErrorToast from "@/components/ErrorToast";
import "./index.css";
import {headers} from 'next/headers'


export default async function QuestionPage({params}) {
    const {questionId} = params;

    try {
        const headerList = headers()
        const cookie = headerList.get('cookie') || ''

        const res = await getQuestionVoByIdUsingGet({
            id: questionId as any,
        }, {
            headers: {
                Cookie: cookie // 携带客户端 cookie
            }
        });
        const question = res.data;

        return (
            <div id="questionPage">
                <QuestionCard question={question}/>
            </div>
        );
    } catch (e) {
        return <ErrorToast error={e.message}/>;
    }
}
